set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

CREATE PROCEDURE [dbo].[AlarmDefine_Insert]
	@AlarmType int,
	@Expression nvarchar(500),
	@CreateBy nvarchar(50)
AS
	INSERT INTO AlarmDefine(AlarmType,Expression,CreateBy,CreateDate)
					 VALUES(@AlarmType,@Expression,@CreateBy,GETDATE())
--------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

CREATE PROCEDURE [dbo].[AlarmDefine_Update]
	@AlarmType int,
	@Expression nvarchar(500),
	@CreateBy nvarchar(50),
	@id int,
	@ModifyBy nvarchar(50)
AS
	UPDATE AlarmDefine
	   SET AlarmType  = @AlarmType,
		   Expression = @Expression,
		   ModifyBy   = @ModifyBy,
		   ModifyDate = getdate()
     WHERE ID = @Id
	   AND CreateBy	  = @CreateBy
-------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[AlarmDefine_Delete]
	@CreateBy nvarchar(50),
	@id int
AS
	DECLARE @SQLQuery AS NVARCHAR(500)
	SET @SQLQuery = 'DELETE AlarmDefine WHERE id IN (' + CAST(@id AS NVARCHAR) + ') AND CreateBy= ''' + @CreateBy + '''';
	EXECUTE(@SQLQuery)
-------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

CREATE PROCEDURE [dbo].[AlarmDefine_GetAll]
	@CreateBy nvarchar(50)
AS
	SELECT *
	  FROM ALARMDEFINE
	 WHERE CreateBy=@CreateBy

